home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: txnews.amd.com!news
- From: Bret Patterson <faustus>
- Subject: RTTI
- Content-Type: text/plain; charset=us-ascii
- Message-ID: <DKzEnw.3vK@txnews.amd.com>
- Sender: news@txnews.amd.com
- Nntp-Posting-Host: fuggles
- Content-Transfer-Encoding: 7bit
- Organization: Advanced Micro Devices, Inc., Austin, Texas, USA
- Mime-Version: 1.0
- Date: Wed, 10 Jan 1996 20:09:30 GMT
- X-Mailer: Mozilla 1.12 (X11; I; HP-UX A.09.05 9000/715)
- X-Url: news:comp.lang.c++
-
- I've just discovered the ability of c++ to do Run Time Type Identification
- using the typeid() class. What I'm wondering is there a way to determine
- if a class is derived from another class?
-
- For example:
-
- class a {};
-
- class b : a {};
-
- class c : a {}
-
- class d : b {};
-
- then I have a function:
-
- void doSomething (a *me)
- {
- if (typeid(me) == derivedFrom(b))
- { doSomethingAlso); };
- else return;
- };
-
- If I pass doSomething an object that was derived from the b branch
- rather than the c branch it will do something special, or likewise.
-
- This can be of obvious use where you have a hierarchy of classes where
- human is the base class and then you spawn off to water dwelling and
- land dwelling and air dwelling. Each with subclasses. This way if
- a human wanted to fly all I would need to do is check if it was
- derived from the air dwelling subtree.
-
- Bret
-
-